import java.util.*;

public class Fleet {
	
	/** private List Plane[] fleetArray;*/
	private LinkedList<Plane> fleetList;

	/**Fleet Constructor*/
	public Fleet(){
		fleetList = new LinkedList<Plane>();
	}
	
	
	/**
	 * Add a Plane to the Fleet.
	 * @param newPlane The new Plane to be added to the Fleet.
	 */
	public void addPlane() {
		fleetList.add(new Plane());
	}

	/**
	 * Creates a new Plane object and the adds it to the Fleet.
	 * 
	 * @param numSeats The number of seats on the Plane
	 * @param routes The route of the Plane
	 * @param size The size of the Plane
	 */
	public void addPlane(int Flight, int numFirstClass, int numEconomy, String newRoute) {
		fleetList.add(new  Plane (Flight, numFirstClass, numEconomy, newRoute));
    }
                
	

	/*
	 * Returns the number of Planes.
	 * 
	 * @return the number of Planes.
	 */
	public int showPlaneAmount(){
		return fleetList.size();
	}
	
	/**
	 * Returns the Xth Plane in the list.
	 * 
	 * @param number The (1-based) numbered plane in the list.
	 * @return The corresponding Plane in the list.
	 * @throws IndexOutOfBoundsException If you put in a negative number, 0,  or
	 *  a number greater than the number of items in the list.
	 */
	public Plane pickAPlane(int number) throws IndexOutOfBoundsException{
		if((number > fleetList.size()) || (number < 1)){
			throw new IndexOutOfBoundsException("your choice is too high.");
		} 
		
		return fleetList.get(number -1);		
	}
    
    /**
        * Returns true or false if Plane exists in Fleet
        * @param flightNumber The plane number from the printFleet() output
        * @return Return true if plane exists, and false if not
    */
    public boolean findPlane(int flightNumber) {
        ListIterator itr = fleetList.listIterator();
        Plane plane = new Plane();
        
        while (itr.hasNext()) {
            plane = ((Plane)itr.next());
            if (flightNumber == plane.getFlightNum()) {
                return true;    
            }
        } 
        
        return false;
    }
    
        /**
        * Returns Plane, assumes flightNumber exists, returns null if Plane does not exist
        * Use findPlane() to confirm flightNumber exists
        * @param flightNumber The plane number from the printFleet() output
        * @return Return plane exists, and false if not
    */
    public Plane getPlane(int flightNumber) {
        ListIterator itr = fleetList.listIterator();
        Plane plane = new Plane();
        
        while (itr.hasNext()) {
            plane = ((Plane)itr.next());
            if (flightNumber == plane.getFlightNum()) {
                return plane;    
            }
        } 
        
        return null;
    }
    
        /**
        * Sets the Plane, if the Plane is in the list (flightNumber search)
        * Assumes Plane exists based on the results of getPlane()
        * @param planeToSave The plane object to save
        * @return void. Returns nothing
    */
    public void setPlane(Plane planeToSave) {
        ListIterator itr = fleetList.listIterator();
        Plane plane = new Plane();
        
        while (itr.hasNext()) {
            plane = ((Plane)itr.next());
            if (planeToSave.getFlightNum() == plane.getFlightNum()) {
                itr.set(planeToSave);
                break;
            }
        } 
    }    
    
    public void printFleetDetail() {
        ListIterator itr = fleetList.listIterator();
        
        while (itr.hasNext()) {
            ((Plane)itr.next()).printSummary();
            System.out.println();
        }
    }
    
    public void printFleet() {
        ListIterator itr = fleetList.listIterator();
        
        while (itr.hasNext()) {
            ((Plane)itr.next()).printFlightNumberAndRoute();
        }        
    }
}
